#!/usr/local/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/9/19 17:04
# @Author  : Kyy
# @Site    : 
# @File    : server.py
# @Software: PyCharm
from flask import Flask
from flask_cors import CORS
import re
from bson import json_util as jsonb
from flask import Response,jsonify,request
from connmongo import MongoConn

app = Flask(__name__)
CORS(app,supports_credentials=True)



@app.route("/robo",methods=['GET','POST','OPTIONS'])
def getinfo():
    stockid = request.args.get('stock')
    print(request.args)
    myconn = MongoConn()
    old_keys = ['股票代码','股票基本信息','主营构成','盈利指标预测','经营数据预测','盈利预测分析','近一年同业公司对比估值','新闻','券商研报','重要公告']
    new_keys = ['stockid','stockinfo','mainoperation','finprediction','mainoperprediction','summary','comparison','news','search','announcements']
    try:
        res = myconn.db['robo'].find_one({'股票代码':stockid},{'_id':0})
        newres = {}
        for i in range(len(old_keys)):
            newres[new_keys[i]] = res[old_keys[i]]
    except Exception as e:
        print(str(e))
        newres = {}
    rst = jsonify(newres)
    return rst

if __name__ == '__main__':
    app.config['JSON_AS_ASCII'] = False
    app.config['JSONIFY_MIMETYPE'] = 'application/json;charset=utf-8'
    app.run(host="0.0.0.0",debug=False)